<?php
class ControllerDelimanMyaccount extends Controller
{
	private $error = array();
   	function __construct() 
	{
		
		$this->load->model("core/user");
	 	$this->load->model("deliman/nhanvien");
		$this->load->model("deliman/khuvuc");
		
   	}
	
	public function index()
	{
		$this->load->model('deliman/loainhanvien');
		$this->data['loainhanviens'] = $this->model_deliman_loainhanvien->getList();
		$this->data['khuvucphutrach'] = array();
		$nhanvienid = $this->user->getNhanVien();
		
		$this->data['item'] = $this->model_deliman_nhanvien->getItem($nhanvienid);
		$where = " AND nhanvienphutrachid = '".$nhanvienid."'";
		$where .= " AND tinhtrang <> 'deleted'";
		$data_khuvucphutrach = $this->model_deliman_nhanvien->getPhuTrachKhuVucList($where);	
    	$this->data['data_khuvucphutrach'] = array();
		foreach($data_khuvucphutrach as $item)
		{
			$arr_khuvuc = $this->model_deliman_khuvuc->getItem($item['khuvucid']);
			$this->data['data_khuvucphutrach'][] = $arr_khuvuc;
		}
		
		$this->id='content';
		$this->template="deliman/myaccount.tpl";
		$this->layout="layout/deliman";
		$this->render();
	}
	
	public function save()
	{
		$this->load->model("deliman/loainhanvien");
		$data = $this->request->post;
		$loainhanvien = $this->model_deliman_loainhanvien->getItem($data['loainhanvienid']);
		$data['tenloainhanvien'] = $loainhanvien['tenloainhanvien'];
		
		if($data['nhanvienid']=="")
		{
			$data['nhanvienid'] = $this->model_deliman_nhanvien->insert($data);	
		}
		else
		{
			$this->model_deliman_nhanvien->update($data);	
		}
		//Cap nhat du lieu qua bang user
		$user['userid'] = $data['userid'];
		$user['username'] = $data['userid'];
		$user['usertypeid'] = 'nhanvien';
		$user['password'] = $data['password'];
		$user['fullname'] = $data['hoten'];
		$user['email'] = $data['email'];
		$user['address'] = $data['diachi'];
		$user['phone'] = $data['dienthoai'];
		$this->model_core_user->updateuser($user);
		
		$this->data['output'] = "true";
		
		$this->id='content';
		$this->template='common/output.tpl';
		$this->render();
	}
	
	
}
?>